package com.jishuo.nontax.bfc.tlq;

import com.tongtech.tmqi.BasicQueue;
import com.tongtech.tmqi.BasicTopic;
import org.springframework.jms.support.destination.DestinationResolver;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Session;
import java.util.HashMap;
import java.util.Map;

/**
 * TLQ DestinationResolver
 */
public class TlqDestinationResolver implements DestinationResolver {

    private Map<String, BasicQueue> queueCache = new HashMap<String,BasicQueue>();
    private Map<String, BasicTopic> topicCache = new HashMap<String,BasicTopic>();

    @Override
    public Destination resolveDestinationName(Session session, String s, boolean flag) throws JMSException {
        if(flag){
            BasicTopic topic = topicCache.get(s);
            if(topic==null){
                topic = new BasicTopic(s);
                topicCache.put(s, topic);
            }
            return topic;
        }else{
            BasicQueue queue = queueCache.get(s);
            if(queue==null){
                queue = new BasicQueue(s);
                queueCache.put(s, queue);
            }
            return queue;
        }
    }
}
